package com.xueyi.aixihu.controller;

import com.xueyi.aixihu.constant.SystemRoleConstant;
import com.xueyi.aixihu.controller.base.BaseController;
import com.xueyi.aixihu.entity.vo.*;
import com.xueyi.aixihu.exception.SzException;
import com.xueyi.aixihu.reqeust.*;
import com.xueyi.aixihu.response.base.BaseResponse;
import com.xueyi.aixihu.service.ReportFormsAuditService;
import com.xueyi.aixihu.status.SystemCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author hxs
 * @createDate 2023/6/29 11:06
 * @description 社区、居委会 财务三资审核接口 【参与角色】镇财政所成员、镇财政所所长
 */
@RestController
public class ReportFormsAuditController extends BaseController {

    @Autowired
    private ReportFormsAuditService reportFormsAuditService;

    /**
     * 查询待审核报表
     *
     * @param findWaitAuditReportFormListReq 参数
     * @return 列表
     */
    @RequestMapping("/audit/reportForm/findWaitAuditReportFormList")
    public BaseResponse<DataList<FindWaitAuditReportFormListVo>> findWaitAuditReportFormList(@Validated FindWaitAuditReportFormListReq findWaitAuditReportFormListReq) throws SzException {
        DtUsersVo user = DtUsersVo.findCurrentUser();
        Integer role = user.getUserMaxRole();
        DataList<FindWaitAuditReportFormListVo> flag = null;
        //镇财政所
        if (SystemRoleConstant.Z_CZS_CY.equals(role) || SystemRoleConstant.Z_CZS_SZ.equals(role)) {
            flag = reportFormsAuditService.findWaitAuditReportFormList(findWaitAuditReportFormListReq);
        }
        //镇经管站
        else if (SystemRoleConstant.Z_JGZ_ZZ.equals(role) || SystemRoleConstant.Z_JGZ_CY.equals(role)) {
            flag = reportFormsAuditService.findAreaFinanceList(findWaitAuditReportFormListReq);
        } else {
            throw new SzException(SystemCode.QUERY_CHECK_ERROR, "没有操作权限~~~");
        }
        return BaseResponse.success(flag);
    }

    /**
     * 查询镇级待审核财务报表
     *
     * @param findTownWaitAuditFinanceListReq 参数
     * @return 列表
     */
    @RequestMapping("/audit/reportForm/findTownWaitAuditFinanceList")
    public BaseResponse<DataList<FindWaitAuditReportFormListVo>> findTownWaitAuditFinanceList(FindTownWaitAuditFinanceListReq findTownWaitAuditFinanceListReq) throws SzException {
        DataList<FindWaitAuditReportFormListVo> flag = reportFormsAuditService.findTownWaitAuditFinanceList(findTownWaitAuditFinanceListReq);
        return BaseResponse.success(flag);
    }

    /**
     * 通过审核
     *
     * @param agreePassAuditReq 参数
     * @return 响应成功
     */
    @RequestMapping("/audit/reportForm/agreePassAudit")
    public BaseResponse<Boolean> agreePassAudit(@Validated AgreePassAuditReq agreePassAuditReq) throws SzException {

        DtUsersVo user = DtUsersVo.findCurrentUser();
        Integer role = user.getUserMaxRole();
        //镇财政所
        if (SystemRoleConstant.Z_CZS_CY.equals(role) || SystemRoleConstant.Z_CZS_SZ.equals(role)) {
            reportFormsAuditService.agreePassAudit(agreePassAuditReq);
        }
        //镇经管站
        else if (SystemRoleConstant.Z_JGZ_ZZ.equals(role) || SystemRoleConstant.Z_JGZ_CY.equals(role)) {
            reportFormsAuditService.agreeThreeAudit(agreePassAuditReq);
        } else {
            throw new SzException(SystemCode.QUERY_CHECK_ERROR, "没有操作权限~~~");
        }
        return BaseResponse.success(Boolean.TRUE);
    }

    /**
     * 查询村级三资审核报表
     *
     * @param findWaitAuditReportFormListReq 参数
     * @return 响应成功
     */
    @RequestMapping("/audit/reportForm/findThreeFinance")
    public BaseResponse<DataList<FindWaitAuditReportFormListVo>> findAreaFinanceList(@Validated FindWaitAuditReportFormListReq findWaitAuditReportFormListReq) throws SzException {
        return BaseResponse.success(reportFormsAuditService.findAreaFinanceList(findWaitAuditReportFormListReq));
    }

    /**
     * 审核村级三资（同意或拒绝）
     *
     * @param agreePassAuditReq
     * @return
     * @throws SzException
     */
    @RequestMapping("/audit/reportForm/agreeThreeReport")
    public BaseResponse<Boolean> agreeThreeAudit(AgreePassAuditReq agreePassAuditReq) throws SzException {
        reportFormsAuditService.agreeThreeAudit(agreePassAuditReq);
        return BaseResponse.success(Boolean.TRUE);
    }


    /**
     * 查询不同状态的条数
     *
     * @param findTownWaitAuditFinanceListReq
     * @return
     */
    @RequestMapping("/audit/reportForm/findFinanceAuditTypeSize")
    public BaseResponse<FinanceExpenseSizeVo> findFinanceAuditTypeSize(FindTownWaitAuditFinanceListReq findTownWaitAuditFinanceListReq) throws SzException {
        return BaseResponse.success(reportFormsAuditService.findFinanceAuditTypeSize(findTownWaitAuditFinanceListReq));
    }

    /**
     * 查询镇级财务报表页面数据
     *
     * @return 页面数据
     */
    @RequestMapping("/audit/reportForm/findWaitFinanceSize")
    public BaseResponse<FindWaitFinanceSizeVo> findWaitFinanceSize(FindWaitFinanceSizeReq findWaitFinanceSizeReq) throws SzException {
        FindWaitFinanceSizeVo flag = reportFormsAuditService.findWaitFinanceSize(findWaitFinanceSizeReq);
        return BaseResponse.success(flag);
    }


    /**
     * 通过报表id查询报表
     *
     * @param id 报表id
     * @return 报表
     */
    @RequestMapping("/audit/reportForm/findFinanceById")
    public BaseResponse<AxhFinanceVo> findFinanceById(Integer id) throws SzException {
        AxhFinanceVo flag = reportFormsAuditService.findFinanceById(id);
        return BaseResponse.success(flag);
    }

    /**
     * 查询报表审核记录日志
     *
     * @param id 报表id
     * @return 日志列表
     */
    @RequestMapping("/audit/reportForm/findReportFormsAuditLog")
    public BaseResponse<List<AxhAuditFinanceLogVo>> findReportFormsAuditLog(Integer id) throws SzException {
        List<AxhAuditFinanceLogVo> list = reportFormsAuditService.findReportFormsAuditLog(id, Boolean.TRUE);
        return BaseResponse.success(list);
    }

    /**
     * 修改报表信息
     *
     * @param updateReportFormInfoReq 参数
     * @return 响应成功
     */
    @RequestMapping("/audit/reportForm/updateReportFormInfo")
    public BaseResponse<Boolean> updateReportFormInfo(@Validated UpdateReportFormInfoReq updateReportFormInfoReq) throws SzException {
        reportFormsAuditService.updateReportFormInfo(updateReportFormInfoReq);
        return BaseResponse.success(Boolean.TRUE);
    }

    /**
     * 转化为草稿
     *
     * @param id 报表id
     * @return 响应成功
     */
    @RequestMapping("/audit/reportForm/transferDraft")
    public BaseResponse<Boolean> transferDraft(Integer id) throws SzException {
        reportFormsAuditService.transferDraft(id);
        return BaseResponse.success(Boolean.TRUE);
    }


}
